"""
Tests that validate the functionality of the module that is responsible for abstracting access to the different
template rendering engines that Cobbler supports.
"""

from cobbler.api import CobblerAPI
from cobbler.templates import Templar


def test_render(cobbler_api: CobblerAPI):
    """
    Test to verify that rendering an empty template returns an empty string.
    """
    # Arrange
    test_templar = Templar(cobbler_api)
    test_templar.load_template_providers()

    # Act
    result = test_templar.render("", {}, None, template_type="cheetah")

    # Assert
    assert result == ""


def test_render_cheetah(cobbler_api: CobblerAPI):
    """
    Test to verify that rendering a simple Cheetah template works as expected.
    """
    # Arrange
    test_templar = Templar(cobbler_api)
    test_templar.load_template_providers()

    # Act
    result = test_templar.render("$test", {"test": 5}, None, "cheetah")

    # Assert
    assert result == "5"


def test_render_jinja2(cobbler_api: CobblerAPI):
    """
    Test to verify that rendering a simple Jinja2 template works as expected.
    """
    # Arrange
    test_templar = Templar(cobbler_api)
    test_templar.load_template_providers()

    # Act
    result = test_templar.render("{{ foo }}", {"foo": "Test successful"}, None, "jinja")

    # Assert
    assert result == "Test successful"


def test_load_template_providers(cobbler_api: CobblerAPI):
    """
    Test to verify that loading the template providers works as expected.
    """
    # Arrange
    test_templar = Templar(cobbler_api)
    test_templar.load_template_providers()

    # Act
    test_templar.load_template_providers()

    # Act
    assert list(
        test_templar.__dict__.get("_Templar__loaded_template_providers", {}).keys()
    ) == ["cheetah", "jinja"]
